﻿#include <QCoreApplication>
#include <QString>
#include <QDebug>
#pragma execution_character_set("utf-8")

int removeDuplicates(QList<int> nums)
{
    for (int i=0; i < nums.length()-1; i++)
    {
        for (int j=i+1; j < nums.length(); j++)
        {
            if(nums[i]==nums[j])
                nums.removeAt(j);//删除元素
        }
    }
    int newLength=nums.length();
    return newLength;
}



int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QList<int> list;
            list<<1<<3<<1<<9<<3<<2<<2<<1;//硬编码输入有序数组nums
    int result = removeDuplicates(list); //删除重复元素并返回删除后数组长度
    qDebug("新数组长度：%d",result);//输出新数组长度
    return a.exec();
}
